#pragma once
#include "T_Ref.h"
#include <vector>

class T_ReleasePool{
private:
	std::vector<T_Ref *>m_Objects;
	T_ReleasePool(){
		m_Objects.reserve(100);
	}
public:
	static T_ReleasePool &getInstance(){
		static T_ReleasePool p;
		return p;
	}
	~T_ReleasePool();
	void add(T_Ref *r);
	bool contains(T_Ref *r);
	void remove(T_Ref *r);
};

class DelayedReleasePool{
private:
	std::vector<T_Ref *>m_Objects;
	DelayedReleasePool(){
		m_Objects.reserve(8);
	}
public:
	static DelayedReleasePool &getInstance(){
		static DelayedReleasePool pool;
		return pool;
	}
	~DelayedReleasePool(){
		clear();
		m_Objects.swap(std::vector<T_Ref *>());
	}
	void add(T_Ref *r){
		if(NULL==r)return;
		for(std::vector<T_Ref *>::iterator i=m_Objects.begin();i!=m_Objects.end();i++){
			if(r==*i)return;
		}
		m_Objects.push_back(r);
	}
	bool empty(){
		return m_Objects.empty();
	}
	void clear(){
		for(std::vector<T_Ref *>::iterator i=m_Objects.begin();i!=m_Objects.end();i++){
			(*i)->release();
		}
		m_Objects.clear();
	}
};
